//
//  WCWindowGradientBottomView.m
//  WabbitCode
//
//  Created by William Towe on 3/25/09.
//  Copyright 2009 Revolution Software. All rights reserved.
//

#import "WCWindowGradientBottomView.h"
#import "NSGradient+WCExtensions.h"
#import "NSColor+WCExtensions.h"


@implementation WCWindowGradientBottomView
- (void)dealloc {
	[[NSNotificationCenter defaultCenter] removeObserver:self];
	[super dealloc];
}

- (void)awakeFromNib {
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeKeyNotification:) name:NSWindowDidBecomeKeyNotification object:[self window]];
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidResignKeyNotification:) name:NSWindowDidResignKeyNotification object:[self window]];
}

- (void)drawRect:(NSRect)rect {
	NSRect bounds = [self bounds];
	NSGradient *gradient = nil;
	NSColor *fillColor = nil;
	
	if ([[self window] isEqualTo:[NSApp keyWindow]] && [NSApp isActive]) {
		gradient = [NSGradient windowActiveFrameGradient];
		fillColor = [NSColor windowActiveFrameBottomLineColor];
	}
	else {
		gradient = [NSGradient windowInactiveFrameGradient];
		fillColor = [NSColor windowInactiveFrameBottomLineColor];
	}
	
	[gradient drawInRect:bounds angle:-90.0];
	[fillColor setFill];
	NSRectFill(NSMakeRect(bounds.origin.x, bounds.origin.y+bounds.size.height-1.0, bounds.size.width, 1.0));
}

- (void)windowDidBecomeKeyNotification:(NSNotification *)note {
	[self setNeedsDisplay:YES];
}

- (void)windowDidResignKeyNotification:(NSNotification *)note {
	[self setNeedsDisplay:YES];
}
@end
